/**
 * Copyright [2010] Delta Air Lines, Inc. All Rights Reserved Access,
 * Modification, or Use Prohibited Without Express Permission of Delta Air
 * Lines.
 */
package com.delta.rafg.coredata;


import java.util.ArrayList;
import java.util.List;


/**
 * AdvisoryMessage.Contains Message properties. Its used to parse massages form
 * list.
 * @author Delta
 * @version 1.0
 * @see AObject
 */
public class AdvisoryMessage extends AObject {

    /**
     * Holds the value of serialVersionUID property.
     */
    private static final long serialVersionUID = -5355701216282090737L;

    /**
     * Holds the value of all property.
     */
    protected List<AdvisoryMessage> all;

    /**
     * Holds the value of freeformText property.
     */
    protected String freeformText;

    /**
     * Holds the value of messageNumber property.
     */
    protected String messageNumber;

    /**
     * Holds the value of process property.
     */
    protected String process;

    /**
     * Holds the value of spare property.
     */
    protected String spare;

    /**
     * Holds the value of sscRequest property.
     */
    protected String sscRequest;

    /**
     * This method is the access method for the <code>all</code> property, which
     * is of type <code>List<AdvisoryMessage></code>.
     * @return the current value of the <code>all</code> property.
     */
    public List<AdvisoryMessage> getAll() {

        if (all == null) {
            all = new ArrayList<AdvisoryMessage>();
        }
        return all;
    }

    /**
     * This method is used to get one String message from List<String>
     * @return
     */
    public String getAllAsString() {

        final StringBuffer strBuff = new StringBuffer();
        for (final AdvisoryMessage next : getAll()) {
            strBuff.append(next.getFreeformText());
        }
        return strBuff.toString();
    }

    /**
     * This method is the access method for the <code>freeformText</code>
     * property, which is of type <code>String</code>.
     * @return the current value of the <code>freeformText</code> property.
     */
    public String getFreeformText() {

        return freeformText;
    }

    /**
     * This method is the access method for the <code>messageNumber</code>
     * property, which is of type <code>String</code>.
     * @return the current value of the <code>messageNumber</code> property.
     */
    public String getMessageNumber() {

        return messageNumber;
    }

    /**
     * This method is the access method for the <code>process</code> property,
     * which is of type <code>String</code>.
     * @return the current value of the <code>process</code> property.
     */
    public String getProcess() {

        return process;
    }

    /**
     * This method is the access method for the <code>spare</code> property,
     * which is of type <code>String</code>.
     * @return the current value of the <code>spare</code> property.
     */
    public String getSpare() {

        return spare;
    }

    /**
     * This method is the access method for the <code>sscRequest</code>
     * property, which is of type <code>String</code>.
     * @return the current value of the <code>sscRequest</code> property.
     */
    public String getSscRequest() {

        return sscRequest;
    }

    /**
     * This method sets the value of the <code>all</code> property, which is of
     * type <code>List<AdvisoryMessage></code>.
     * @param all - the new value of <code>all</code> property.
     */
    public void setAll(final List<AdvisoryMessage> all) {

        this.all = all;
    }

    /**
     * This method sets the value of the <code>freeformText</code> property,
     * which is of type <code>String</code>.
     * @param freeformText - the new value of <code>freeformText</code>
     *            property.
     */
    public void setFreeformText(final String freeformText) {

        this.freeformText = freeformText;
    }

    /**
     * This method sets the value of the <code>messageNumber</code> property,
     * which is of type <code>String</code>.
     * @param messageNumber - the new value of <code>messageNumber</code>
     *            property.
     */
    public void setMessageNumber(final String messageNumber) {

        this.messageNumber = messageNumber;
    }

    /**
     * This method sets the value of the <code>process</code> property, which is
     * of type <code>String</code>.
     * @param process - the new value of <code>process</code> property.
     */
    public void setProcess(final String process) {

        this.process = process;
    }

    /**
     * This method sets the value of the <code>spare</code> property, which is
     * of type <code>String</code>.
     * @param value - the new value of <code>spare</code> property.
     */
    public void setSpare(final String value) {

        spare = value;
    }

    /**
     * This method sets the value of the <code>sscRequest</code> property, which
     * is of type <code>String</code>.
     * @param sscRequest - the new value of <code>sscRequest</code> property.
     */
    public void setSscRequest(final String sscRequest) {

        this.sscRequest = sscRequest;
    }
    
    /**
     * @param pLineNum
     * @param pStart
     * @param pLength
     * @return
     */
    public String subText(int pLineNum, int pStart, int pLength) {
        String retStr = "";
        
        if ( pLineNum < 1 || pStart < 1 || pLength < 1 )
            return retStr;
        
        pLineNum = pLineNum - 1;
        pStart = pStart - 1;
        pLength = pStart + pLength;
        
        List<AdvisoryMessage> advMsgs = getAll();

        if ( advMsgs.size() >= (pLineNum + 1) && advMsgs.get(pLineNum).getFreeformText() != null ) {
            
            if ( advMsgs.get(pLineNum).getFreeformText().length() >= pLength )
                retStr = advMsgs.get(pLineNum).getFreeformText().substring(pStart, pLength);
        }
        
        return retStr.trim();
    }
}
